#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int Leap_year(int y)
{
	if ((y % 4 == 0 && y % 100!= 0 )|| y % 400 == 0)
	{
		return 1;
	}
	return 0;
}

int Days(int r,int month,int* p)
{
	if (r == 1)
	{
		*(p + 2) = 29;
	}
	else
	{
		*(p + 2) = 28;
	}
	return *(p + month);
}

int main()
{
	int year = 0;
	int month = 0;
	int Day[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	while (scanf("%d %d", &year, &month) != EOF)
	{
		int r = Leap_year(year);
		int day = Days(r, month, Day);
		printf("%d\n", day);
	}
	return 0;
}